﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace YacGE
{
    public static class ExtensionMethods
    {
        public static Texture2D ConvertToPreMultipliedAlpha(this Texture2D texture)
        {
            Color[] data = new Color[texture.Width * texture.Height];
            texture.GetData<Color>(data, 0, data.Length);
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = new Color(new Vector4(data[i].ToVector3() * (data[i].A / 255f), (data[i].A / 255f)));
            }
            texture.SetData<Color>(data, 0, data.Length);

            return texture;
        }
    }  
}
